package org.stragma.symbian.units;

import org.stragma.apply.signatures.Apply;
import org.stragma.apply.signatures.Apply.TModule;

import org.stragma.symbian.apply.stratego.Simplify;
import org.stragma.symbian.*;

import org.stragma.util.Configuration;
import org.stragma.apply.signatures.Options.*;

/**
 * Simplify unit represents simplification as a testable unit wrapped in
 * an implementation of the strategy pattern
 * @author Shirren
 *
 */
public class SimplifyUnit implements ITestable {

	/**
	 * Primary method for testing a Kiama unit in Stragma. For example
	 * Normalise would implement this method as it has been implemented in Stragma
	 */
	@Override
	public void testKiama(String testDataSource) {
		
		// Set these default options. The Apply java unit has been pre-compiled
		// with these options
		Configuration.set_configHelper(new Propagate_constant_assignments(), true);
		Configuration.set_configHelper(new Normalise_expressions(), true);
		Configuration.set_configHelper(new Evaluate_constant_expressions(), false);
	
		// An instance is required here as the DoApply class holds state and so
		//and instance of a class if required
		org.stragma.apply.modules.Simplify simplify = new org.stragma.apply.modules.Simplify();
		TModule res = (TModule)simplify.simplifyHelper(testDataSource, 1);
		Apply.TModuleToATerm(res);
	}

	/**
	 * Corollary to the Kiama unit this method is for testing Stratego
	 */
	@Override
	public void testStratego(String testDataSource) {			
		String[] newArgs = new String[]{"-i", testDataSource};
		Simplify.main(newArgs);
	}
}